﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;

namespace YJKFurniture.LayoutFurnitures
{
	public partial class LayoutAlongFurnitureForm : System.Windows.Forms.Form
	{
		public LayoutAlongFurnitureForm()
		{
			this.InitializeComponent();
			//base.Icon = Resource.YArchitechIcon;
		}

		private void LayoutAlongFurnitureForm_Load(object sender, EventArgs e)
		{
			this.InitUserSetting();
			this.m_nSpace = Convert.ToInt32(this.txtSpace.Text);
			this.m_nOffset = Convert.ToInt32(this.txtOffset.Text);
			this.m_nNum = (int)this.nudNum.Value;
		}

		private void SetUserData()
		{
			this.m_userSetting.ReloadFile();
			this.m_userSetting.WriteValue("FurnitureLayout", "AlongFurnitureOffset", this.txtOffset.Text);
			this.m_userSetting.WriteValue("FurnitureLayout", "AlongFurnitureSpace", this.txtSpace.Text);
			this.m_userSetting.WriteValue("FurnitureLayout", "AlongFurnitureNum", this.nudNum.Value.ToString());
		}

		private void InitUserSetting()
		{
			try
			{
				string value = this.m_userSetting.GetValue("FurnitureLayout", "AlongFurnitureNum");
				if (value == null || value == "")
				{
					this.nudNum.Value = this.m_nNum;
				}
				else
				{
					this.nudNum.Value = Convert.ToInt32(value);
				}
				string value2 = this.m_userSetting.GetValue("FurnitureLayout", "AlongFurnitureSpace");
				if (value2 == null || value2 == "")
				{
					this.txtSpace.Text = this.m_nSpace.ToString();
				}
				else
				{
					this.txtSpace.Text = value2;
				}
				string value3 = this.m_userSetting.GetValue("FurnitureLayout", "AlongFurnitureOffset");
				if (value3 == null || value3 == "")
				{
					this.txtOffset.Text = this.m_nOffset.ToString();
				}
				else
				{
					this.txtOffset.Text = value3;
				}
			}
			catch
			{
			}
		}

		private void txtOffset_TextChanged(object sender, EventArgs e)
		{
			try
			{
				this.m_nOffset = Convert.ToInt32(this.txtOffset.Text);
			}
			catch
			{
				this.txtOffset.Text = this.m_nOffset.ToString();
			}
		}

		private void txtSpace_TextChanged(object sender, EventArgs e)
		{
			try
			{
				this.m_nSpace = Convert.ToInt32(this.txtSpace.Text);
			}
			catch
			{
				this.txtSpace.Text = this.m_nSpace.ToString();
			}
		}

		private void nudNum_ValueChanged(object sender, EventArgs e)
		{
			if ((int)this.nudNum.Value < 1)
			{
				YJKMessageBox.Show("设备数量必须大于等于1", MessageBoxButtons.OK);
				this.nudNum.Value = this.m_nNum;
				return;
			}
			this.m_nNum = (int)this.nudNum.Value;
		}

		private void btnSure_Click(object sender, EventArgs e)
		{
			try
			{
				this.SetUserData();
				this.m_nSpace = Convert.ToInt32(this.txtSpace.Text);
				this.m_nOffset = Convert.ToInt32(this.txtOffset.Text);
				this.m_nNum = (int)this.nudNum.Value;
			}
			catch
			{
			}
		}

		private void btnCancle_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void LayoutAlongFurnitureForm_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
		}

		private void LayoutAlongFurnitureForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (base.DialogResult != DialogResult.OK)
			{
				return;
			}
			this.SetUserData();
		}

		public int m_nOffset;

		public int m_nSpace = 1500;

		public int m_nNum = 1;

		private UserSetting m_userSetting = new UserSetting();
	}
}
